﻿#include "lualib_user.h"
#include "lua_obj.h"

/*
** these libs are loaded by lua.c and are readily available to any Lua
** program
*/
static const luaL_Reg loadedlibs[] = {
#ifndef F1C100S
    {LUA_ARRAYLIBNAME, lua_array_funinit},
#endif // !F1C100S
    {LUA_USERLIBNAME, lua_user_funinit},
    {LUA_LVGLLIBNAME, lua_lvgl_funinit},
    {LUA_ANIMLIBNAME, lua_lv_anim_funinit},
    {LUA_ARCLIBNAME, lua_lv_arc_funinit},
    {LUA_BARLIBNAME, lua_lv_bar_funinit},
    {LUA_BTNLIBNAME, lua_lv_btn_funinit},
    {LUA_BTNMATRIXLIBNAME, lua_lv_btnmatrix_funinit},
    {LUA_CANVASLIBNAME, lua_lv_canvas_funinit},
    {LUA_CHECKBOXLIBNAME, lua_lv_checkbox_funinit},
    {LUA_DROPDOWNLIBNAME, lua_lv_dropdown_funinit},
    {LUA_IMGLIBNAME, lua_lv_img_funinit},
    {LUA_LABELLIBNAME, lua_lv_label_funinit},
    {LUA_LINELIBNAME, lua_lv_line_funinit},
    {LUA_OBJX_TEMPLLIBNAME, lua_lv_objx_templ_funinit},
    {LUA_ROLLERLIBNAME, lua_lv_roller_funinit},
    {LUA_SLIDERLIBNAME, lua_lv_slider_funinit},
    {LUA_SWITCHLIBNAME, lua_lv_switch_funinit},
    {LUA_TABLELIBNAME, lua_lv_table_funinit},
    {LUA_TEXTAREALIBNAME, lua_lv_textarea_funinit},
    {NULL, NULL}};

LUALIB_API void luaL_openlibs_user(lua_State *L)
{
    const luaL_Reg *lib;
    /* "require" functions from 'loadedlibs' and set results to global table */
    for (lib = loadedlibs; lib->func; lib++)
    {
        luaL_requiref(L, lib->name, lib->func, 1);
        lua_pop(L, 1); /* remove lib */
    }
}
